<template>
  <div>
    <el-row :gutter="15">

      <el-tabs v-model="activexdivdv" tab-position="top" class="mb-20">
        <el-tab-pane label="原数据">

          <el-form ref="elForm" :disabled="true" :model="dataForm.oldData" size="small" label-width="100px"
                   label-position="right"
          >
            <template>
              <!--          v-if="!loading && formOperates"-->
              <el-card class="mb-20" shadow="always" header="基础信息">
                <el-col :span="6" v-if="judgeShow('contractNumber')"
                >
                  <el-form-item label="合同编号"
                                prop="contractNumber"
                  >
                    <el-input v-model="dataForm.oldData.contractNumber"
                              placeholder="请输入" :disabled="judgeWrite('contractNumber')" clearable
                              :style='{"width":"100%"}'
                    >

                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="6" v-if="judgeShow('contractType')"
                >
                  <el-form-item label="合同类型"
                                prop="contractType"
                  >
                    <el-select v-model="dataForm.oldData.contractType"
                               placeholder="请选择" :disabled="judgeWrite('contractType')" clearable
                               :style='{"width":"100%"}'
                    >
                      <el-option v-for="(item, index) in contractTypeOptions" :key="index" :label="item.fullName"
                                 :value="item.id" :disabled="item.disabled"
                      ></el-option>

                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="6" v-if="judgeShow('project')"
                >
                  <el-form-item label="项目"
                                prop="project"
                  >
                    <el-select v-model="dataForm.oldData.project"
                               placeholder="请选择" :disabled="judgeWrite('project')" clearable :style='{"width":"100%"}'
                    >
                      <el-option v-for="(item, index) in projectOptions" :key="index" :label="item.fullName"
                                 :value="item.id" :disabled="item.disabled"
                      ></el-option>

                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="6" v-if="judgeShow('relatedContracts')"
                >
                  <el-form-item label="关联合同"
                                prop="relatedContracts"
                  >
                    <el-select v-model="dataForm.oldData.relatedContracts"
                               placeholder="请选择" :disabled="judgeWrite('relatedContracts')" clearable
                               :style='{"width":"100%"}'
                    >
                      <el-option v-for="(item, index) in relatedContractsOptions" :key="index" :label="item.fullName"
                                 :value="item.id" :disabled="item.disabled"
                      ></el-option>

                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8" v-if="judgeShow('signingDate')"
                >
                  <el-form-item label="签订日期"
                                prop="signingDate"
                  >
                    <el-date-picker v-model="dataForm.oldData.signingDate"
                                    placeholder="请选择" :disabled="judgeWrite('signingDate')" clearable
                                    :style='{"width":"100%"}' type="date" format="yyyy-MM-dd" value-format="timestamp"
                    >

                    </el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="8" v-if="judgeShow('effectiveDate')"
                >
                  <el-form-item label="生效日期"
                                prop="effectiveDate"
                  >
                    <el-date-picker v-model="dataForm.oldData.effectiveDate"
                                    placeholder="请选择" :disabled="judgeWrite('effectiveDate')" clearable
                                    :style='{"width":"100%"}' type="date" format="yyyy-MM-dd" value-format="timestamp"
                    >

                    </el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="8" v-if="judgeShow('purposeHouse')"
                >
                  <el-form-item label="房屋用途"
                                prop="purposeHouse"
                  >
                    <el-input v-model="dataForm.oldData.purposeHouse"
                              placeholder="请输入" :disabled="judgeWrite('purposeHouse')" clearable
                              :style='{"width":"100%"}'
                    >

                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="14" v-if="judgeShow('contractHandler')"
                >
                  <el-form-item label="合同经办人"
                                prop="contractHandler"
                  >
                    <user-select v-model="dataForm.oldData.contractHandler"
                                 placeholder="请选择" :disabled="judgeWrite('contractHandler')" clearable
                    >

                    </user-select>
                  </el-form-item>
                </el-col>
                <el-col :span="10" v-if="judgeShow('ihis')"
                >
                  <el-form-item label="是否为历史合同"
                                prop="ihis"
                  >
                    <el-switch v-model="dataForm.oldData.ihis"
                               :disabled="judgeWrite('ihis')" :active-value="1" :inactive-value="0"
                    >

                    </el-switch>
                  </el-form-item>
                </el-col>
                <el-col :span="14" v-if="judgeShow('notes')"
                >
                  <el-form-item label="备注"
                                prop="notes"
                  >
                    <el-input v-model="dataForm.oldData.notes"
                              placeholder="请输入" :disabled="judgeWrite('notes')" :style='{"width":"100%"}' true
                              type="textarea" :autosize='{"minRows":4,"maxRows":4}'
                    >

                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-card class="mb-20" shadow="always" header="甲方" style="margin-top:15px">
                    <el-col :span="10" v-if="judgeShow('partyName')"
                    >
                      <el-form-item label="甲方名称"
                                    prop="partyName"
                      >
                        <el-select v-model="dataForm.oldData.partyName"
                                   placeholder="请选择" :disabled="judgeWrite('partyName')" clearable
                                   :style='{"width":"100%"}'
                        >
                          <el-option v-for="(item, index) in partyNameOptions" :key="index" :label="item.fullName"
                                     :value="item.id" :disabled="item.disabled"
                          ></el-option>

                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="10" v-if="judgeShow('partyBusinessLicense')"
                    >
                      <el-form-item label="甲方营业执照"
                                    prop="partyBusinessLicense"
                      >
                        <el-input v-model="dataForm.oldData.partyBusinessLicense"
                                  placeholder="请输入" :disabled="judgeWrite('partyBusinessLicense')" clearable
                                  :style='{"width":"100%"}'
                        >

                        </el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="10" v-if="judgeShow('partyContacts')"
                    >
                      <el-form-item label="甲方联系人"
                                    prop="partyContacts"
                      >
                        <el-input v-model="dataForm.oldData.partyContacts"
                                  placeholder="请输入" :disabled="judgeWrite('partyContacts')" clearable
                                  :style='{"width":"100%"}'
                        >

                        </el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="10" v-if="judgeShow('partyContactInformation')"
                    >
                      <el-form-item label="甲方联系方式"
                                    prop="partyContactInformation"
                      >
                        <el-input v-model="dataForm.oldData.partyContactInformation"
                                  placeholder="请输入" :disabled="judgeWrite('partyContactInformation')" clearable
                                  :style='{"width":"100%"}'
                        >

                        </el-input>
                      </el-form-item>
                    </el-col>
                  </el-card>
                </el-col>
                <el-col :span="24">
                  <el-card class="mb-20" shadow="always" header="乙方客户信息">
                    <el-col :span="24" v-if="judgeShow('zcglhtglpabList') && formOperates">
                      <el-form-item label-width="0">
                        <div class="JNPF-common-title">
                          <h2></h2>
                        </div>
                        <el-table :data="dataForm.oldData.zcgl_htgl_pab" size="mini">
                          <el-table-column type="index" width="80" label="序号" align="center"/>
                          <el-table-column prop="pabCustomerName" label="乙方客户名称" width="180" align="center"
                                           v-if="judgeShow('zcglhtglpabList-pabCustomerName')"
                          >
                            <template slot-scope="scope">
                              <el-form-item :prop="'zcgl_htgl_pab.' + scope.$index + '.pabCustomerName'"
                              >
                                <el-select

                                  v-model="scope.row.pabCustomerName" placeholder="请选择"
                                  :disabled="judgeWrite('zcglhtglpabList') || judgeWrite('zcglhtglpabList-pabCustomerName')"
                                  clearable :style='{"width":"100%"}'
                                  @change="handleCustomerNameChange(scope.$index, scope.row)"
                                >
                                  <el-option v-for="(item, index) in kfList" :key="index" :label="item.fullName"
                                             :value="item.id" :disabled="item.disabled"
                                  >
                                  </el-option>
                                </el-select>
                              </el-form-item>
                            </template>
                          </el-table-column>
                          <el-table-column prop="pabContactNumber" label="乙方联系电话"
                                           v-if="judgeShow('zcglhtglpabList-pabContactNumber')"
                          >

                            <template slot-scope="scope">
                              <el-form-item :prop="'zcgl_htgl_pab.' + scope.$index + '.pabContactNumber'"
                              >
                                <el-input v-model="scope.row.pabContactNumber"
                                          placeholder="请输入"
                                          :disabled="judgeWrite('zcglhtglpabList') || judgeWrite('zcglhtglpabList-pabContactNumber')"
                                          clearable :style='{"width":"100%"}'
                                >
                                </el-input>
                              </el-form-item>
                            </template>
                          </el-table-column>

                          <el-table-column prop="pabIdType" label="乙方证件类型" v-if="judgeShow('zcglhtglpabList-pabIdType')"
                          >
                            <template slot="header" v-if="judgeRequired('zcglhtglpabList-pabIdType')">
                              <span class="required-sign">*</span>乙方证件类型
                            </template>
                            <template slot-scope="scope">
                              <el-select v-model="scope.row.pabIdType"
                                         placeholder="请选择"
                                         :disabled="judgeWrite('zcglhtglpabList') || judgeWrite('zcglhtglpabList-pabIdType')"
                                         clearable :style='{"width":"100%"}'
                              >
                                <el-option v-for="(item, index) in pabIdTypeOptions" :key="index" :label="item.fullName"
                                           :value="item.id" :disabled="item.disabled"
                                ></el-option>
                              </el-select>
                            </template>
                          </el-table-column>
                          <el-table-column prop="pabIdNo" label="乙方证件号码" v-if="judgeShow('zcglhtglpabList-pabIdNo')"
                          >
                            <template slot="header" v-if="judgeRequired('zcglhtglpabList-pabIdNo')">
                              <span class="required-sign">*</span>乙方证件号码
                            </template>
                            <template slot-scope="scope">
                              <el-input v-model="scope.row.pabIdNo"
                                        placeholder="请输入"
                                        :disabled="judgeWrite('zcglhtglpabList') || judgeWrite('zcglhtglpabList-pabIdNo')"
                                        clearable :style='{"width":"100%"}'
                              >
                              </el-input>
                            </template>
                          </el-table-column>
                          <el-table-column prop="pabContactAddress" label="乙方联系地址"
                                           v-if="judgeShow('zcglhtglpabList-pabContactAddress')"
                          >
                            <template slot="header" v-if="judgeRequired('zcglhtglpabList-pabContactAddress')">
                              <span class="required-sign">*</span>乙方联系地址
                            </template>
                            <template slot-scope="scope">
                              <el-input v-model="scope.row.pabContactAddress"
                                        placeholder="请输入"
                                        :disabled="judgeWrite('zcglhtglpabList') || judgeWrite('zcglhtglpabList-pabContactAddress')"
                                        clearable :style='{"width":"100%"}'
                              >
                              </el-input>
                            </template>
                          </el-table-column>
                          <el-table-column label="操作" width="70"
                                           v-if="!setting.readonly && !judgeWrite('zcglhtglpabList')"
                          >
                            <template slot-scope="scope">
                              <el-button size="mini" type="text" class="JNPF-table-delBtn"
                                         @click="delzcglhtglpabList(scope.$index)"
                              >删除
                              </el-button>
                            </template>
                          </el-table-column>
                        </el-table>
                        <div class="table-actions" @click="addzcglhtglpabList()">
                          <el-button type="text" icon="el-icon-plus">添加</el-button>
                        </div>
                      </el-form-item>
                    </el-col>
                  </el-card>
                </el-col>
              </el-card>
            </template>
          </el-form>
        </el-tab-pane>

        <el-tab-pane label="变更数据">

          <el-form ref="elForm" :model="dataForm.newData" :rules="dataRule" size="small" label-width="100px"
                   label-position="right" :disabled="setting.readonly"
          >
            <template>
              <el-card class="mb-30" shadow="always" header="终止原因">
                <el-col :span="14"
                >
                  <el-form-item label="终止原因"
                                prop="remarks"
                                style="margin-bottom: 15px"
                  >
                    <el-input v-model="dataForm.remarks"
                              placeholder="请输入" :disabled="judgeWrite('remarks')" :style='{"width":"100%"}' true
                              type="textarea" :autosize='{"minRows":4,"maxRows":3}'
                    >

                    </el-input>
                  </el-form-item>
                </el-col>
              </el-card>

              <!--          v-if="!loading && formOperates"-->
              <el-card class="mb-20" shadow="always" header="基础信息">
                <el-col :span="6" v-if="judgeShow('contractNumber')"
                >
                  <el-form-item label="合同编号"
                                prop="contractNumber"
                  >
                    <el-input v-model="dataForm.newData.contractNumber"
                              placeholder="请输入" :disabled="judgeWrite('contractNumber')" clearable
                              :style='{"width":"100%"}'
                    >

                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="6" v-if="judgeShow('contractType')"
                >
                  <el-form-item label="合同类型"
                                prop="contractType"
                  >
                    <el-select v-model="dataForm.newData.contractType"
                               placeholder="请选择" :disabled="judgeWrite('contractType')" clearable
                               :style='{"width":"100%"}'
                    >
                      <el-option v-for="(item, index) in contractTypeOptions" :key="index" :label="item.fullName"
                                 :value="item.id" :disabled="item.disabled"
                      ></el-option>

                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="6" v-if="judgeShow('project')"
                >
                  <el-form-item label="项目"
                                prop="project"
                  >
                    <el-select v-model="dataForm.newData.project"
                               placeholder="请选择" :disabled="judgeWrite('project')" clearable :style='{"width":"100%"}'
                    >
                      <el-option v-for="(item, index) in projectOptions" :key="index" :label="item.fullName"
                                 :value="item.id" :disabled="item.disabled"
                      ></el-option>

                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="6" v-if="judgeShow('relatedContracts')"
                >
                  <el-form-item label="关联合同"
                                prop="relatedContracts"
                  >
                    <el-select v-model="dataForm.newData.relatedContracts"
                               placeholder="请选择" :disabled="judgeWrite('relatedContracts')" clearable
                               :style='{"width":"100%"}'
                    >
                      <el-option v-for="(item, index) in relatedContractsOptions" :key="index" :label="item.fullName"
                                 :value="item.id" :disabled="item.disabled"
                      ></el-option>

                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8" v-if="judgeShow('signingDate')"
                >
                  <el-form-item label="签订日期"
                                prop="signingDate"
                  >
                    <el-date-picker v-model="dataForm.newData.signingDate"
                                    placeholder="请选择" :disabled="judgeWrite('signingDate')" clearable
                                    :style='{"width":"100%"}' type="date" format="yyyy-MM-dd" value-format="timestamp"
                    >

                    </el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="8" v-if="judgeShow('effectiveDate')"
                >
                  <el-form-item label="生效日期"
                                prop="effectiveDate"
                  >
                    <el-date-picker v-model="dataForm.newData.effectiveDate"
                                    placeholder="请选择" :disabled="judgeWrite('effectiveDate')" clearable
                                    :style='{"width":"100%"}' type="date" format="yyyy-MM-dd" value-format="timestamp"
                    >

                    </el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="8" v-if="judgeShow('purposeHouse')"
                >
                  <el-form-item label="房屋用途"
                                prop="purposeHouse"
                  >
                    <el-input v-model="dataForm.newData.purposeHouse"
                              placeholder="请输入" :disabled="judgeWrite('purposeHouse')" clearable
                              :style='{"width":"100%"}'
                    >

                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="14" v-if="judgeShow('contractHandler')"
                >
                  <el-form-item label="合同经办人"
                                prop="contractHandler"
                  >
                    <user-select v-model="dataForm.newData.contractHandler"
                                 placeholder="请选择" :disabled="judgeWrite('contractHandler')" clearable
                    >

                    </user-select>
                  </el-form-item>
                </el-col>
                <el-col :span="10" v-if="judgeShow('ihis')"
                >
                  <el-form-item label="是否为历史合同"
                                prop="ihis"
                  >
                    <el-switch v-model="dataForm.newData.ihis"
                               :disabled="judgeWrite('ihis')" :active-value="1" :inactive-value="0"
                    >

                    </el-switch>
                  </el-form-item>
                </el-col>
                <el-col :span="14" v-if="judgeShow('notes')"
                >
                  <el-form-item label="备注"
                                prop="notes"
                  >
                    <el-input v-model="dataForm.newData.notes"
                              placeholder="请输入" :disabled="judgeWrite('notes')" :style='{"width":"100%"}' true
                              type="textarea" :autosize='{"minRows":4,"maxRows":4}'
                    >

                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-card class="mb-20" shadow="always" header="甲方" style="margin-top:15px">
                    <el-col :span="10" v-if="judgeShow('partyName')"
                    >
                      <el-form-item label="甲方名称"
                                    prop="partyName"
                      >
                        <el-select v-model="dataForm.newData.partyName"
                                   placeholder="请选择" :disabled="judgeWrite('partyName')" clearable
                                   :style='{"width":"100%"}'
                        >
                          <el-option v-for="(item, index) in partyNameOptions" :key="index" :label="item.fullName"
                                     :value="item.id" :disabled="item.disabled"
                          ></el-option>

                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="10" v-if="judgeShow('partyBusinessLicense')"
                    >
                      <el-form-item label="甲方营业执照"
                                    prop="partyBusinessLicense"
                      >
                        <el-input v-model="dataForm.newData.partyBusinessLicense"
                                  placeholder="请输入" :disabled="judgeWrite('partyBusinessLicense')" clearable
                                  :style='{"width":"100%"}'
                        >

                        </el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="10" v-if="judgeShow('partyContacts')"
                    >
                      <el-form-item label="甲方联系人"
                                    prop="partyContacts"
                      >
                        <el-input v-model="dataForm.newData.partyContacts"
                                  placeholder="请输入" :disabled="judgeWrite('partyContacts')" clearable
                                  :style='{"width":"100%"}'
                        >

                        </el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="10" v-if="judgeShow('partyContactInformation')"
                    >
                      <el-form-item label="甲方联系方式"
                                    prop="partyContactInformation"
                      >
                        <el-input v-model="dataForm.newData.partyContactInformation"
                                  placeholder="请输入" :disabled="judgeWrite('partyContactInformation')" clearable
                                  :style='{"width":"100%"}'
                        >

                        </el-input>
                      </el-form-item>
                    </el-col>
                  </el-card>
                </el-col>
                <el-col :span="24">
                  <el-card class="mb-20" shadow="always" header="乙方客户信息">
                    <el-col :span="24" v-if="judgeShow('zcglhtglpabList') && formOperates">
                      <el-form-item label-width="0">
                        <div class="JNPF-common-title">
                          <h2></h2>
                        </div>
                        <el-table :data="dataForm.newData.zcgl_htgl_pab">
                          <el-table-column type="index" width="70" label="序号"/>
                          <el-table-column prop="pabCustomerName" label="乙方客户名称" width="180"
                                           v-if="judgeShow('zcglhtglpabList-pabCustomerName')"
                          >
                            <template slot-scope="scope">
                              <el-form-item :prop="'zcgl_htgl_pab.' + scope.$index + '.pabCustomerName'"
                              >
                                <el-select v-model="scope.row.pabCustomerName" placeholder="请选择"
                                           :disabled="judgeWrite('zcglhtglpabList') || judgeWrite('zcglhtglpabList-pabCustomerName')"
                                           clearable :style='{"width":"100%"}'
                                           @change="handleCustomerNameChange(scope.$index, scope.row)"
                                >
                                  <el-option v-for="(item, index) in kfList" :key="index" :label="item.fullName"
                                             :value="item.id" :disabled="item.disabled"
                                  >
                                  </el-option>
                                </el-select>
                              </el-form-item>
                            </template>
                          </el-table-column>
                          <el-table-column prop="pabContactNumber" label="乙方联系电话"
                                           v-if="judgeShow('zcglhtglpabList-pabContactNumber')"
                          >

                            <template slot-scope="scope">
                              <el-form-item :prop="'zcgl_htgl_pab.' + scope.$index + '.pabContactNumber'"
                              >
                                <el-input v-model="scope.row.pabContactNumber"
                                          placeholder="请输入"
                                          :disabled="judgeWrite('zcglhtglpabList') || judgeWrite('zcglhtglpabList-pabContactNumber')"
                                          clearable :style='{"width":"100%"}'
                                >
                                </el-input>
                              </el-form-item>
                            </template>
                          </el-table-column>
                          <el-table-column prop="pabIdType" label="乙方联系电话"
                                           v-if="judgeShow('zcglhtglpabList-pabContactNumber')"
                          >

                            <template slot-scope="scope">
                              <el-form-item :prop="'zcgl_htgl_pab.' + scope.$index + '.pabContactNumber'"
                              >
                                <el-input v-model="scope.row.pabContactNumber"
                                          placeholder="请输入"
                                          :disabled="judgeWrite('zcglhtglpabList') || judgeWrite('zcglhtglpabList-pabContactNumber')"
                                          clearable :style='{"width":"100%"}'
                                >
                                </el-input>
                              </el-form-item>
                            </template>
                          </el-table-column>
                          <el-table-column prop="pabIdType" label="乙方证件类型" v-if="judgeShow('zcglhtglpabList-pabIdType')"
                          >

                            <template slot-scope="scope">
                              <el-select v-model="scope.row.pabIdType"
                                         placeholder="请选择"
                                         :disabled="judgeWrite('zcglhtglpabList') || judgeWrite('zcglhtglpabList-pabIdType')"
                                         clearable :style='{"width":"100%"}'
                              >
                                <el-option v-for="(item, index) in pabIdTypeOptions" :key="index" :label="item.fullName"
                                           :value="item.id" :disabled="item.disabled"
                                ></el-option>
                              </el-select>
                            </template>
                          </el-table-column>
                          <el-table-column prop="pabIdNo" label="乙方证件号码" v-if="judgeShow('zcglhtglpabList-pabIdNo')"
                          >

                            <template slot-scope="scope">
                              <el-input v-model="scope.row.pabIdNo"
                                        placeholder="请输入"
                                        :disabled="judgeWrite('zcglhtglpabList') || judgeWrite('zcglhtglpabList-pabIdNo')"
                                        clearable :style='{"width":"100%"}'
                              >
                              </el-input>
                            </template>
                          </el-table-column>
                          <el-table-column prop="pabContactAddress" label="乙方联系地址"
                                           v-if="judgeShow('zcglhtglpabList-pabContactAddress')"
                          >

                            <template slot-scope="scope">
                              <el-input v-model="scope.row.pabContactAddress"
                                        placeholder="请输入"
                                        :disabled="judgeWrite('zcglhtglpabList') || judgeWrite('zcglhtglpabList-pabContactAddress')"
                                        clearable :style='{"width":"100%"}'
                              >
                              </el-input>
                            </template>
                          </el-table-column>
                          <el-table-column label="操作" width="70"
                                           v-if="!setting.readonly && !judgeWrite('zcglhtglpabList')"
                          >
                            <template slot-scope="scope">
                              <el-button size="mini" type="text" class="JNPF-table-delBtn"
                                         @click="delzcglhtglpabList(scope.$index)"
                              >删除
                              </el-button>
                            </template>
                          </el-table-column>
                        </el-table>
                        <div class="table-actions" @click="addzcglhtglpabList()">
                          <el-button type="text" icon="el-icon-plus">添加</el-button>
                        </div>
                      </el-form-item>
                    </el-col>
                  </el-card>
                </el-col>

              </el-card>
            </template>
          </el-form>
        </el-tab-pane>
      </el-tabs>


    </el-row>
    <UserBox v-if="userBoxVisible" ref="userBox" @submit="submit"/>
    <SelectDialog v-if="selectDialogVisible" :config="addTableConf" :formData="dataForm" ref="selectDialog"
                  @select="addForSelect" @close="selectDialogVisible=false"
    />
  </div>
</template>

<script>
import request from '@/utils/request'
import { getDataInterfaceRes } from '@/api/systemData/dataInterface'
import { getDictionaryDataSelector } from '@/api/systemData/dictionary'
import SelectDialog from '@/components/SelectDialog'

export default {
  components: { SelectDialog },
  props: [],
  data() {
    return {
      zcNatureOptions: [],
      zcNatureProps: { 'label': 'fullName', 'value': 'id' },
      zcPurposeOptions: [],
      zcPurposeProps: { 'label': 'fullName', 'value': 'id' },
      zcSourceOptions: [],
      zcSourceProps: { 'label': 'fullName', 'value': 'id' },
      affiliatedUnitOptions: [],
      affiliatedUnitProps: { 'label': 'fullName', 'value': 'id' },
      managementUnitOptions: [],
      managementUnitProps: { 'label': 'fullName', 'value': 'id' },
      jnpf_zcgl_zcdj_warrant_jnpf_propertyRightOptions: [],
      jnpf_zcgl_zcdj_warrant_jnpf_propertyRightProps: { 'label': 'fullName', 'value': 'id' },
      jnpf_zcgl_zcdj_warrant_jnpf_useNatureOptions: [],
      jnpf_zcgl_zcdj_warrant_jnpf_useNatureProps: { 'label': 'fullName', 'value': 'id' },
      activexdivdv: '1',
      selectDialogVisible: false,
      tableKey: '',
      addTableConf: {},
      loading: false,
      visible: false,
      setting: {},
      eventType: '',
      userBoxVisible: false,
      tableRequiredData: {},
      primaryKeyPolicy: true,
      dataFormNew: {},
      dataForm: {
        oldData: {

          zcNumber: ''
        },
        newData: {},
        id: '',
        flowId: '',
        status: 1,
        candidateList: {},
        freeapproveruserid: '',
        branchList: [],
        errorRuleUserList: {},
        flowUrgent: 1,
        version: 0,
        flowtaskid: undefined,
        copyIds: '',
        project: '',
        customerName: '',
        contractNo: '',
        paymentBy: '',
        billType: '',
        expenseStartDate: '',
        expenseEndDate: '',
        planReceiptDate: '',
        billRemark: '',
        zcbillitemList: []
      },
      KfList: [],
      dataRule:
        {},
      zcgl_cw_bill_itemexpenseItemOptions: [{ 'fullName': '选项一', 'id': '1' }, { 'fullName': '选项二', 'id': '2' }],
      zcgl_cw_bill_itemexpenseItemProps: { 'label': 'fullName', 'value': 'id' }
    }
  },
  computed: {
    formOperates() {
      return this.setting.formOperates
    }
  },
  watch: {},
  created() {
    // this.getColumnList(),
    this.getKhList()
    this.getcontractTypeOptions()
    this.getprojectOptions()
    this.getpaymentDeadlineTypeOptions()
    this.getpaymentDeadlineStatusOptions()

  },
  mounted() {
  },
  methods: {
    getKhList() {

      request({
        url: '/api/example/ZcglCustomer/getAllList',
        method: 'post'
      }).then(res => {
        this.kfList = res.data
      })

    },
    getcontractTypeOptions() {
      getDictionaryDataSelector('622532919440706373').then(res => {
        this.contractTypeOptions = res.data.list
      })
    },
    getprojectOptions() {
      getDictionaryDataSelector('622532443626277701').then(res => {
        this.projectOptions = res.data.list
      })
    },
    getpaymentDeadlineTypeOptions() {
      getDictionaryDataSelector('622533108956138312').then(res => {
        this.paymentDeadlineTypeOptions = res.data.list
      })
    },
    getpaymentDeadlineStatusOptions() {
      getDictionaryDataSelector('622533108956138313').then(res => {
        this.paymentDeadlineStatusOptions = res.data.list
      })
    },
    updateDataRule() {
      let newRules = {}
      for (let i = 0; i < this.setting.formOperates.length; i++) {
        const item = this.setting.formOperates[i]
        if (!item.id.includes('-')) {
          const newRulesItem = {
            required: item.required || false,
            message: item.name + '不能为空',
            trigger: item.trigger || 'blur'
          }
          if (!this.dataRule.hasOwnProperty(item.id)) {
            if (item.required) this.$set(newRules, item.id, [newRulesItem])
          } else {
            let withoutRequiredItem = true
            for (let i = 0; i < this.dataRule[item.id].length; i++) {
              if (this.dataRule[item.id][i].hasOwnProperty('required')) {
                this.dataRule[item.id][i].required = item.required || false
                withoutRequiredItem = false
              }
            }
            if (withoutRequiredItem && item.required) this.dataRule[item.id].push(newRulesItem)
          }
        } else {
          let key = item.id.split('-')[0]
          let newId = item.id.split('-')[1]
          let newItem = {
            ...item,
            id: newId
          }
          if (!this.tableRequiredData.hasOwnProperty(key)) {
            this.$set(this.tableRequiredData, key, [newItem])
          } else {
            this.tableRequiredData[key].push(newItem)
          }
        }
      }
      this.dataRule = { ...this.dataRule, ...newRules }
    },
    exist() {
      let isOk = true
      let messageList = []
      for (let key in this.tableRequiredData) {
        let arr = this.tableRequiredData[key].filter((o) => o.required) || []
        for (let k = 0; k < arr.length; k++) {
          for (let i = 0; i < this.dataForm[key].length; i++) {
            let id = arr[k].id
            let name = arr[k].name
            let _data = this.dataForm[key][i][id]
            let boo = true
            if (Array.isArray(_data)) {
              boo = !this.jnpf.isEmptyArray(_data)
            } else {
              boo = !this.jnpf.isEmpty(_data)
            }
            if (!boo) {
              messageList.push(name + '不能为空')
            }
          }
        }
      }
      isOk = messageList.length == 0
      if (messageList.length > 0) {
        this.$message.error(messageList[0], 1000)
      }
      return isOk
    },
    dataAll() {
    },
    goBack() {
      this.$emit('refresh')
    },
    init(data) {
      if (data.flowTaskInfo != null) {

        console.log(data.flowTaskInfo)

        this.dataInfo3(data.flowTaskInfo.flowFormContentJson)
        this.$emit('setPageLoad')
        this.$store.commit('generator/UPDATE_RELATION_DATA', {})
        this.loading = false
        // this.dataForm.id = data.id || "";
        this.setting = data
        // this.visible = true;
        this.updateDataRule()

      } else {
        this.$store.commit('generator/UPDATE_RELATION_DATA', {})
        this.loading = true
        this.dataForm.id = data.id || ''
        this.setting = data
        this.visible = true

        this.$nextTick(() => {
          // this.$refs['elForm'].resetFields();
          if (this.dataForm.id) {
            let url = '/api/example/ZcglHtglInfo/' + this.dataForm.id
            if (this.dataForm.flowtaskid) {
              url += '?flowtaskid=' + this.dataForm.flowtaskid
            }
            request({
              url: url,
              method: 'get'
            }).then(res => {
              this.dataInfo(res.data)
              this.updateDataRule()
            })
          }
          this.loading = false
          this.$emit('setPageLoad')
        })
      }

    },
    // 表单提交
    dataFormSubmit(eventType, flowUrgent) {
      this.$refs['elForm'].validate((valid) => {
        if (valid) {
          if (!this.exist()) return
          if (eventType === 'audit' || eventType === 'reject') {
            var _data = this.dataList()
            this.$emit('eventReceiver', _data, eventType)
            return
          }
          this.dataForm.status = eventType === 'submit' ? 0 : 1
          this.dataForm.flowUrgent = flowUrgent
          this.dataForm.flowId = this.setting.flowId
          this.eventType = eventType
          if (this.eventType === 'submit') {
            this.$confirm('您确定要提交当前流程吗, 是否继续?', '提示', {
              type: 'warning'
            }).then(() => {
              this.request()
            }).catch(() => {
            })
          } else {
            this.request()
          }
        }
      })
    },
    request() {
      var _data = this.dataList()
      var id = this.dataForm.id
      delete this.dataForm.id
      // _data.oldData  = this.dataForm
      // _data.newData  = this.dataFormNew
      _data.type = '4'
      _data.htdgId = id
      if (true) {
        request({
          url: '/api/example/ZcglHtglInfoChange',
          method: 'post',
          data: _data
        }).then((res) => {
          this.$message({
            message: res.msg,
            type: 'success',
            duration: 1000,
            onClose: () => {
              this.visible = false
              this.$emit('close', true)
            }
          })
        })
      } else {
        request({
          url: '/api/ZcglCwBillChange/' + this.dataForm.id,
          method: 'PUT',
          data: _data
        }).then((res) => {
          this.$message({
            message: res.msg,
            type: 'success',
            duration: 1000,
            onClose: () => {
              this.visible = false
              this.$emit('close', true)
            }
          })
        })
      }
    },
    judgeShow(id) {
      if (!this.setting.formOperates || !this.setting.formOperates.length) return true
      let arr = this.setting.formOperates.filter(o => o.id === id) || []
      if (!arr.length) return true
      let item = arr[0]
      return item.read
    },
    judgeWrite(id) {

      if (!this.setting.formOperates || !this.setting.formOperates.length) return false
      let arr = this.setting.formOperates.filter(o => o.id === id) || []

      if (!arr.length) return true
      let item = arr[0]
      return !item.write
    },
    judgeRequired(id) {
      if (!this.setting.formOperates || !this.setting.formOperates.length) return false
      let arr = this.setting.formOperates.filter(o => o.id === id) || []
      if (!arr.length) return true
      let item = arr[0]
      return item.required
    },
    addzcbillitemList() {
      this.tableKey = 'zcbillitemList'
      let item = {
        expenseItem: undefined,
        receiveAmount: undefined
      }
      this.dataForm.zcbillitemList.push(item)
    },
    delzcbillitemList(index) {
      this.dataForm.zcbillitemList.splice(index, 1)
    },
    dataList() {
      var _data = JSON.parse(JSON.stringify(this.dataForm))

      return _data
    },
    dataInfo3(dataAll) {

      let _dataAll = JSON.parse(dataAll)

      console.log('asas阿萨·' + _dataAll)

      function safeParseJSON(data) {
        try {
          return typeof data === 'string' ? JSON.parse(data) : data
        } catch (e) {
          console.error('Parsing error:', e)
          return null // 或者根据需要返回其他默认值
        }
      }

// 处理 oldData 中的 zcFile 和 zcFmImage
      if (_dataAll.oldData) {
        let oldDataParsed = safeParseJSON(_dataAll.oldData)
        if (oldDataParsed) {
          if (oldDataParsed.zcFile != '') {
            oldDataParsed.zcFile = oldDataParsed.zcFile ? JSON.parse(oldDataParsed.zcFile) : []

          }
          if (oldDataParsed.zcFmImage != '') {
            oldDataParsed.zcFmImage = oldDataParsed.zcFmImage ? JSON.parse(oldDataParsed.zcFmImage) : []

          }

        }
      }

// 处理 newData 中的 zcFile 和 zcFmImage
      if (_dataAll.newData) {
        let newDataParsed = safeParseJSON(_dataAll.newData)
        if (newDataParsed) {
          if (newDataParsed.zcFile != '') {
            newDataParsed.zcFile = newDataParsed.zcFile ? JSON.parse(newDataParsed.zcFile) : []

          }
          if (newDataParsed.zcFmImage != '') {
            newDataParsed.zcFmImage = newDataParsed.zcFmImage ? JSON.parse(newDataParsed.zcFmImage) : []

          }

        }
      }

      this.dataForm = _dataAll
      if (typeof this.dataForm.oldData === 'string') {

        this.dataForm.oldData = JSON.parse(this.dataForm.oldData)

      } else {
        this.dataForm.oldData = this.dataForm.oldData
      }

      if (typeof this.dataForm.newData === 'string') {
        this.dataForm.newData = JSON.parse(this.dataForm.newData)

      } else {
        this.dataForm.newData = this.dataForm.newData
      }

      // this.dataFormNew = JSON.parse(JSON.stringify(this.dataForm))
    },
    dataInfo(dataAll) {
      let _dataAll = dataAll
      if (_dataAll.zcFile != null && dataAll.zcFile != '') {
        _dataAll.zcFile = JSON.parse(_dataAll.zcFile)

      } else {
        _dataAll.zcFile = ''
      }
      if (_dataAll.zcFmImage != null && dataAll.zcFmImage != '') {
        _dataAll.zcFmImage = JSON.parse(_dataAll.zcFmImage)

      } else {
        _dataAll.zcFmImage = ''
      }
      this.dataForm.oldData = _dataAll

      this.dataForm.newData = JSON.parse(JSON.stringify(this.dataForm.oldData))
      // this.dataFormNew = JSON.parse(JSON.stringify(this.dataForm))
    },
    dataInfo2(dataAll) {
      let _dataAll = dataAll

      if (_dataAll.zcFile != null && dataAll.zcFile != '') {
        _dataAll.zcFile = JSON.parse(_dataAll.zcFile)

      } else {
        _dataAll.zcFile = ''
      }
      if (_dataAll.zcFmImage != null && dataAll.zcFmImage != '') {
        _dataAll.zcFmImage = JSON.parse(_dataAll.zcFmImage)

      } else {
        _dataAll.zcFmImage = ''
      }
      this.dataForm = _dataAll
      this.$forceUpdate()

    },
    dataInfo1(dataAll) {
      let _dataAll = dataAll
      // for(let i=0;i<_dataAll.zcbillitemList.length;i++){
      //   var _list = _dataAll.zcbillitemList[i];
      //   _list.expenseItem = _list.expenseItem
      // }
      if (_dataAll.zcFile != null && dataAll.zcFile != '') {
        _dataAll.zcFile = JSON.parse(_dataAll.zcFile)

      } else {
        _dataAll.zcFile = ''
      }
      this.dataForm.newData = _dataAll
    },
    addForSelect(data) {
      for (let i = 0; i < data.length; i++) {
        let item = data[i]
        this.dataForm[this.tableKey].push(item)
      }
    }
  }
}

</script>
<style scoped="scoped">
/*!* 增加表格行高 *!*/
/*/deep/ .el-table .el-table__row {*/
/*  height: 53px; !* 你想要的行高 *!*/
/*  border: 1px slategrey solid;*/
/*  color: black;*/
/*}*/

/*!* 如果你还想要调整单元格内部的垂直居中 *!*/
/*/deep/ .el-table .cell {*/
/*  font-size: 16px;*/
/*  color: black;*/
/*  text-align: center;*/
/*  height: 50px; !* 和行高一致 *!*/
/*  line-height: 44px; !* 垂直居中文本 *!*/

/*}*/
.el-form-item {
  margin: 0;
  padding: 0;
}

.el-input, .el-select {
  height: 46px; /* 设置一个固定高度 */
  line-height: 46px;
}
</style>
